//
//  ZDBReceiveCustomAlearView.m
//  ZDB
//
//  Created by Kk on 2020/3/23.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBReceiveCustomAlearView.h"
#pragma make --控件
@interface ZDBReceiveCustomAlearView()
@property(nonatomic,strong)UIView * bgView;
@property(nonatomic,strong)UILabel * titleLab;
@property(nonatomic,strong)UILabel * priceLab;
@property(nonatomic,strong)UILabel * task1Lab;
@property(nonatomic,strong)UILabel * task2Lab;
@property(nonatomic,strong)UILabel * task3Lab;
@property(nonatomic,strong)UIButton * submitBtn;

@end

@implementation ZDBReceiveCustomAlearView

- (instancetype)initWithtiprice:(NSString *)price;
{
    if (self=[super init])
    {
        self.frame=[UIScreen mainScreen].bounds;
        self.backgroundColor=[UIColor colorWithWhite:.0 alpha:.6];

        [self addSubview:self.bgView];
        [_bgView addSubview:self.titleLab];
         [_bgView addSubview:self.priceLab];
        [_bgView addSubview:self.task1Lab];
        [_bgView addSubview:self.task2Lab];
        [_bgView addSubview:self.task3Lab];
        [_bgView addSubview:self.submitBtn];
        
       NSString * titleStr = kFormat(@"该任务计入周榜大奖赛\n(可获得最高%@额外奖励)", price);
     _priceLab.attributedText = [ZBDUnit finderattributedLinesString:titleStr attributedString:price color:MAINCOLOR font:AutoBoldFont(12)];
     _priceLab.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}
- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RealValue_W(540), RealValue_W(520))];
        _bgView.center =self.center;
        _bgView.backgroundColor=WHITECOLOR;
        KViewRadius(_bgView, 4);
    }
    return _bgView;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, _bgView.width, 20)];
        _titleLab.font = AutoBoldFont(16);
        _titleLab.textColor = MAINCOLOR;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.text = @"领取任务成功！";
    }
    return _titleLab;
}
- (UILabel *)priceLab
{
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:CGRectMake(20, _titleLab.bottom+10, _bgView.width-40, 40)];
        _priceLab.font = AutoFont(12);
        _priceLab.textColor = MAINTITLECOLOR;
       
        _priceLab.numberOfLines = 0;
       
    }
    return _priceLab;
}
- (UILabel *)task1Lab
{
    if (!_task1Lab) {
        _task1Lab = [[UILabel alloc] initWithFrame:CGRectMake(41, _priceLab.bottom+15, _bgView.width-51, 20)];
        _task1Lab.font = AutoFont(12);
        _task1Lab.textColor = MAINTITLECOLOR;
        _task1Lab.numberOfLines = 0;
        _task1Lab.text  = @"保存内容，发布朋友圈";
        UILabel * red = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, 18, 18)];
        KViewRadius(red, 9);
        red.textColor = WHITECOLOR;
        red.backgroundColor = MAINCOLOR;
        red.font = AutoFont(12);
        red.textAlignment = NSTextAlignmentCenter;
        red.text = @"1";
        red.centerY = _task1Lab.centerY;
        [_bgView addSubview:red];
    }
    return _task1Lab;
}
- (UILabel *)task2Lab
{
    if (!_task2Lab) {
        _task2Lab = [[UILabel alloc] initWithFrame:CGRectMake(41, _task1Lab.bottom+4, _bgView.width-51, 40)];
        _task2Lab.font = AutoFont(12);
        _task2Lab.textColor = MAINTITLECOLOR;
        _task2Lab.numberOfLines = 0;
        NSString * str = @"发布完成后，前往“我的-任务列表\n或在“详情”页面提交审核截图";
        _task2Lab.attributedText  = [ZBDUnit finderattributedString:str attributedArray:@[@"我的-任务列表",@"详情"] colors:@[MAINCOLOR,MAINCOLOR] font:AutoBoldFont(12)];
        
        UILabel * red = [[UILabel alloc] initWithFrame:CGRectMake(14, _task2Lab.mj_y+2, 18, 18)];
        KViewRadius(red, 9);
        red.textColor = WHITECOLOR;
        red.backgroundColor = MAINCOLOR;
        red.font = AutoFont(12);
        red.textAlignment = NSTextAlignmentCenter;
        red.text = @"2";
         
        [_bgView addSubview:red];
    }
    return _task2Lab;
}
- (UILabel *)task3Lab
{
    if (!_task3Lab) {
        _task3Lab = [[UILabel alloc] initWithFrame:CGRectMake(41, _task2Lab.bottom+4, _bgView.width-51, 40)];
        _task3Lab.font = AutoFont(12);
        _task3Lab.textColor = MAINTITLECOLOR;
        _task3Lab.numberOfLines = 0;
        NSString * str = @"审核完成，资金到账，请随时关注\n钱包刷新";
        _task3Lab.attributedText  = [ZBDUnit finderattributedLinesString:str attributedString:str color:MAINTITLECOLOR font:AutoFont(12)];
        
        
        UILabel * red = [[UILabel alloc] initWithFrame:CGRectMake(14, _task3Lab.mj_y+2, 18, 18)];
        KViewRadius(red, 9);
        red.textColor = WHITECOLOR;
        red.backgroundColor = MAINCOLOR;
        red.font = AutoFont(12);
        red.textAlignment = NSTextAlignmentCenter;
        red.text = @"3";
        [_bgView addSubview:red];
    }
    return _task3Lab;
}
- (UIButton *)submitBtn
{
    if (!_submitBtn) {
        _submitBtn = [[UIButton alloc] initWithFrame:CGRectMake(_bgView.width/2 -  RealValue_W(210)/2, _bgView.height - RealValue_W(92), RealValue_W(210), RealValue_W(48))];
        [_submitBtn setTitleColor:WHITECOLOR forState:0];
        _submitBtn.titleLabel.font = AutoBoldFont(12);
        KViewRadius(_submitBtn, RealValue_W(24));
        _submitBtn.backgroundColor = TABTITLECOLOR;
        [_submitBtn setTitle:@"我知道了" forState:0];
        [_submitBtn addTarget:self action:@selector(submitBtn:) forControlEvents:(UIControlEventTouchUpInside)];
       
    }
    return _submitBtn;
}
- (void)submitBtn:(UIButton *)sender
{
    [self dismissAlertView];
}
- (void)dismissAlertView
{
    [self removeFromSuperview];
}
-(void)showLXAlertView
{
    [kWindow addSubview:self];
    [self setShowAnimation];
}
-(void)setShowAnimation{
    WeakSelf;
    switch (_animationStyle) {
            
        case LXASAnimationDefault:
        {
            [UIView animateWithDuration:0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                [weakSelf.bgView.layer setValue:@(0) forKeyPath:@"transform.scale"];
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:0.23 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    [weakSelf.bgView.layer setValue:@(1.2) forKeyPath:@"transform.scale"];
                } completion:^(BOOL finished) {
                    [UIView animateWithDuration:0.09 delay:0.02 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                        [weakSelf.bgView.layer setValue:@(.9) forKeyPath:@"transform.scale"];
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:0.05 delay:0.02 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                            [weakSelf.bgView.layer setValue:@(1.0) forKeyPath:@"transform.scale"];
                        } completion:^(BOOL finished) {
                            weakSelf.userInteractionEnabled = YES;
                        }];
                    }];
                }];
            }];
        }
            break;
            
        case LXASAnimationLeftShake:{
            
            CGPoint startPoint = CGPointMake(-_bgView.width, self.center.y);
            weakSelf.bgView.layer.position=startPoint;
            
            //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
            //velocity:弹性复位的速度
            [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                weakSelf.bgView.layer.position=self.center;
                
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
            
        case LXASAnimationTopShake:{
            
            CGPoint startPoint = CGPointMake(self.center.x, -_bgView.frame.size.height);
            _bgView.layer.position=startPoint;
            
            //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
            //velocity:弹性复位的速度
            [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                weakSelf.bgView.layer.position=self.center;
                
            } completion:^(BOOL finished) {
                
            }];
        }
            break;
            
        case LXASAnimationNO:{
            
        }
            
            break;
            
        default:
            break;
    }
}
@end
